const express = require('express');

const router = express();
const  dao = require('./dao')
const {LONG} = require("mysql/lib/protocol/constants/types");

// 登录页
router.get('/',function (req,res){
    res.end('index')
})
// 主人页
router.get("/a", (req, res) => {
    const query = req.query;
    const username = query.username;
    const pwd = query.password;
    dao.loginUser(res,username,pwd);

})
// 商店页
router.get("/b", (req, res) => {
    console.log('456')
    const query = req.query;
    const username = query.username;
    const pwd = query.password;
    dao.loginStore(res,username,pwd)
})
// 购买信息
router.get("/table", (req, res) => {
    console.log('789')
    const query = req.query;
    const username = query.username;
    dao.selectPet(res,username)
})

// 个人信息
router.get("/list", (req, res) => {
    console.log('101')
    const query = req.query;
    const owner_id = query.owner_id;
    dao.selectOwner(res,owner_id)

})

router.get("/buy", (req, res) => {
    console.log('buy')
    const query= req.query;
    const petid = query.petid;
    const petstoreid = query.petstoreid;
    const petownerid = query.petownerid;
    dao.updatePetOwner(petownerid,1);
    dao.updatePetStore(petstoreid,2);
    dao.ownerBuy(petownerid,petstoreid,petid);
    dao.addAccount(petownerid,petstoreid,petid,1)

})
router.get("/sell", (req, res) => {
    console.log('666')
    const query = req.query;
    const petid = query.petid;
    const petstoreid = query.petstoreid;
    const petownerid = query.petownerid;
    dao.updatePetOwner(petownerid,2);
    dao.updatePetStore(petstoreid,1);
    dao.ownerSell(petownerid,petstoreid,petid);
    dao.addAccount(petownerid,petstoreid,petid,2)
})

router.get("/store", (req, res) => {
    console.log('555')
    dao.selectStore(res)

})
router.get("/sp", (req, res) => {
    console.log('77777')
    const query = req.query;
    const store_id = query.store_id;
    dao.selectMyStorePet(res,store_id)
})

router.get("/spp", (req, res) => {
    console.log('555')
    dao.selectStoreOwner(res)

})
router.get("/az", (req, res) => {
    console.log('555')
    dao.selectMyOwnerPet(res)

})
router.get("/storebuy", (req, res) => {
    console.log('1211')
    const query = req.query;
    const petid = query.petid;
    const petstoreid = query.petstoreid;
    const petownerid = query.petownerid;
    dao.updatePetOwner(petownerid,2);
    dao.updatePetStore(petstoreid,1);
    dao.ownerBuy(petid,petstoreid,petownerid)
    dao.addAccount(petid,petstoreid,petownerid,2)

})
router.get("/storesell", (req, res) => {
    console.log('1211')
    const query = req.query;
    const petid = query.petid;
    const petstoreid = query.petstoreid;
    const petownerid = query.petownerid;
    dao.updatePetOwner(petownerid,1);
    dao.updatePetStore(petstoreid,2);
    dao.ownerBuy(petownerid,petstoreid,petid);
    dao.addAccount(petownerid,petstoreid,petid,1)

})
module.exports= router;
